package com.coding365.rpcprovider.handler;

import com.coding365.rpcprovider.proxy.JdkDynamicProxy;
import com.lagou.entity.RpcRequest;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 自定义的业务处理器
 */
@Service
public class UserServiceHandler extends ChannelInboundHandlerAdapter {

    @Autowired
    private JdkDynamicProxy jdkDynamicProxy;

    //当客户端读取数据时,该方法会被调用
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

        if(msg instanceof RpcRequest){
            Object result = jdkDynamicProxy.doProxy((RpcRequest) msg);
            ctx.writeAndFlush(result);
        }

    }
}
